<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
  <link href="https://gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="Hugo 0.78.1" />

  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Hugo &middot; My Blog</title>
  <meta name="description" content="" />

  
  <link type="text/css" rel="stylesheet" href="https://colin0724.gitee.io/css/print.css" media="print">
  <link type="text/css" rel="stylesheet" href="https://colin0724.gitee.io/css/poole.css">
  <link type="text/css" rel="stylesheet" href="https://colin0724.gitee.io/css/syntax.css">
  <link type="text/css" rel="stylesheet" href="https://colin0724.gitee.io/css/hyde.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Abril+Fatface|PT+Sans:400,400i,700">


  
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link rel="shortcut icon" href="/favicon.png">

  
  
</head>

  <body class=" ">
  <aside class="sidebar">
  <div class="container sidebar-sticky">
    <div class="sidebar-about">
      <a href="https://colin0724.gitee.io/"><h1>My Blog</h1></a>
      <p class="lead">
      An elegant open source and mobile first theme for <a href="http://hugo.spf13.com">hugo</a> made by <a href="http://twitter.com/mdo">@mdo</a>. Originally made for Jekyll.
      </p>
    </div>

    <nav>
      <ul class="sidebar-nav">
        <li><a href="https://colin0724.gitee.io/">Home</a> </li>
        
      </ul>
    </nav>

    <p>&copy; 2020. All rights reserved. </p>
  </div>
</aside>

    <main class="content container">
    <div class="post">
  <h1>Hugo</h1>
  <time datetime=2020-11-11T11:58:28&#43;0800 class="post-date">Wed, Nov 11, 2020</time>
  <h1 id="快速开始">快速开始</h1>
<h3 id="安装hugo">安装Hugo</h3>
<h4 id="1-二进制安装推荐简单快速">1. 二进制安装（推荐：简单、快速）</h4>
<p>到 <a href="https://github.com/spf13/hugo/releases">Hugo Releases</a> 下载对应的操作系统版本的Hugo二进制文件（hugo或者hugo.exe）</p>
<p>Mac下直接使用 <code>Homebrew</code> 安装：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">brew install hugo
</code></pre></div><h4 id="2-源码安装">2. 源码安装</h4>
<p>源码编译安装，首先安装好依赖的工具：</p>
<ul>
<li><a href="http://git-scm.com/">Git</a></li>
<li><a href="http://mercurial.selenic.com/">Mercurial</a></li>
<li><a href="http://golang.org/">Go</a> 1.3+ (Go 1.4+ on Windows)</li>
</ul>
<p>设置好 <code>GOPATH</code> 环境变量，获取源码并编译：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ export GOPATH<span style="color:#f92672">=</span>$HOME/go
$ go get -v github.com/spf13/hugo
</code></pre></div><p>源码会下载到 <code>$GOPATH/src</code> 目录，二进制在 <code>$GOPATH/bin/</code></p>
<p>如果需要更新所有Hugo的依赖库，增加 <code>-u</code> 参数：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ go get -u -v github.com/spf13/hugo
</code></pre></div><h3 id="生成站点">生成站点</h3>
<p>使用Hugo快速生成站点，比如希望生成到 <code>/path/to/site</code> 路径：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ hugo new site /path/to/site
</code></pre></div><p>这样就在 <code>/path/to/site</code> 目录里生成了初始站点，进去目录：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ cd /path/to/site
</code></pre></div><p>站点目录结构：</p>
<pre><code>  ▸ archetypes/
  ▸ content/
  ▸ layouts/
  ▸ static/
    config.toml
</code></pre><h3 id="创建文章">创建文章</h3>
<p>创建一个 <code>about</code> 页面：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ hugo new about.md
</code></pre></div><p><code>about.md</code> 自动生成到了 <code>content/about.md</code> ，打开 <code>about.md</code> 看下：</p>
<pre><code>+++
date = &quot;2015-10-25T08:36:54-07:00&quot;
draft = true
title = &quot;about&quot;

+++

正文内容
</code></pre><p>内容是 <code>Markdown</code> 格式的，<code>+++</code> 之间的内容是 <a href="https://github.com/toml-lang/toml">TOML</a> 格式的，根据你的喜好，你可以换成 <a href="http://www.yaml.org/">YAML</a> 格式（使用 <code>---</code> 标记）或者 <a href="http://www.json.org/">JSON</a> 格式。</p>
<p>创建第一篇文章，放到 <code>post</code> 目录，方便之后生成聚合页面。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ hugo new post/first.md
</code></pre></div><p>打开编辑 <code>post/first.md</code> ：</p>
<pre><code>---
date: &quot;2015-10-25T08:36:54-07:00&quot;
title: &quot;first&quot;
 
---

### Hello Hugo

 1. aaa
 1. bbb
 1. ccc
</code></pre><h3 id="安装皮肤">安装皮肤</h3>
<p>到 <a href="https://www.gohugo.org/theme/">皮肤列表</a> 挑选一个心仪的皮肤，比如你觉得 <code>Hyde</code> 皮肤不错，找到相关的 <code>GitHub</code> 地址，创建目录 <code>themes</code>，在 <code>themes</code> 目录里把皮肤 <code>git clone</code> 下来：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 创建 themes 目录</span>
$ cd themes
$ git clone https://github.com/spf13/hyde.git
</code></pre></div><h3 id="运行hugo">运行Hugo</h3>
<p>在你的站点根目录执行 <code>Hugo</code> 命令进行调试：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ hugo server --theme<span style="color:#f92672">=</span>hyde --buildDrafts
</code></pre></div><p>（注明：v0.15 版本之后，不再需要使用 <code>--watch</code> 参数了）</p>
<p>浏览器里打开： <code>http://localhost:1313</code></p>
<h3 id="部署">部署</h3>
<p>假设你需要部署在 <code>GitHub Pages</code> 上，首先在GitHub上创建一个Repository，命名为：<code>coderzh.github.io</code> （coderzh替换为你的github用户名）。</p>
<p>在站点根目录执行 <code>Hugo</code> 命令生成最终页面：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ hugo --theme<span style="color:#f92672">=</span>hyde --baseUrl<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;http://coderzh.github.io/&#34;</span>
</code></pre></div><p>（注意，以上命令并不会生成草稿页面，如果未生成任何文章，请去掉文章头部的 <code>draft=true</code> 再重新生成。）</p>
<p>如果一切顺利，所有静态页面都会生成到 <code>public</code> 目录，将pubilc目录里所有文件 <code>push</code> 到刚创建的Repository的 <code>master</code> 分支。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ cd public
$ git init
$ git remote add origin https://github.com/coderzh/coderzh.github.io.git
$ git add -A
$ git commit -m <span style="color:#e6db74">&#34;first commit&#34;</span>
$ git push -u origin master
</code></pre></div><p>浏览器里访问：<code>http://coderzh.github.io/</code></p>

</div>


    </main>

    
      
    
  </body>
</html>
